package com.tutu.thymeleaf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.Map;

/**
 * @Program: SpringBoot
 * @Description: 字符串拼接
 * @Author: JK.TuTu
 * @ @Version: 1.0
 * @Create: 2022-11-30 20:32
 **/
@Controller
@RequestMapping("demo1")
public class TestController06 {
    /**
     * 字符串拼接
     * @param model
     * @return
     */
    @GetMapping("test01")
    public String test01(Model model) {
        model.addAttribute("name","张三");
        model.addAttribute("age",18);
        return "demo10";
    }

    /**
     * 运算符
     * @param model
     * @return
     */
    @GetMapping("test02")
    public String test02(Model model) {
        model.addAttribute("sex","男");
        model.addAttribute("isLogin",true);
        return "demo11";
    }


    /**
     * 内置对象
     * @param
     * @return
     */
    @GetMapping("test03")
    public String test03(Map<String, Object> map, HttpServletRequest request, HttpSession session) {
        map.put("name","kkm789012");
        map.put("hireDate",new Date());
        map.put("num",99.12);
        // 向request域放数据
        request.setAttribute("msg","requestMessage");
        // 向session域放数据
        session.setAttribute("msg","sessionMessage");
        // 向application域放数据
        request.getServletContext().setAttribute("msg","applicationMessage");
        return "demo12";
    }

    /**
     * 模板复用
     * @param model
     * @return
     */
    @GetMapping("test04")
    public String test04(Model model) {
        return "demo13";
    }
}
